package com.yykj.prescription.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.vo.ResultVO;
import com.yykj.prescription.client.dto.PrescriptionCheckMemberDTO;
import com.yykj.prescription.client.dto.PrescriptionSettingDTO;
import com.yykj.prescription.client.dto.PrescriptionTipsDTO;
import com.yykj.prescription.server.dto.prescription.PrescriptionMemberDeleteDTO;
import com.yykj.prescription.server.dto.prescription.PrescriptionMemberEditDTO;
import com.yykj.prescription.server.model.entity.prescription.PrescriptionNoteType;
import com.yykj.prescription.server.model.entity.setting.PrescriptionSetting;
import com.yykj.prescription.server.model.entity.setting.PrescriptionTips;
import com.yykj.prescription.server.service.PrescriptionNoteTypeService;
import com.yykj.prescription.server.service.PrescriptionSettingService;
import com.yykj.prescription.server.service.PrescriptionTipsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "后台 -- 处方设置相关接口")
@RestController
@RequestMapping("/api/prescription")
public class PrescriptionSettingController {

    @ApiOperation("处方设置 -- 添加修改")
    @PostMapping("/setting/edit")
    public ResultVO<PrescriptionSetting> editPrescriptionSetting(@RequestBody PrescriptionSetting setting) {
        return ResultVO.success(settingService.editPrescriptionSetting(setting));
    }

    @GetMapping("/setting/view/{hospitalId}")
    @ApiOperation("处方设置 -- 查看")
    public ResultVO<PrescriptionSettingDTO> viewPrescriptionSetting(@PathVariable Integer hospitalId) {
        PrescriptionSetting prescriptionSetting = settingService.getPrescriptionSetting(hospitalId);
        PrescriptionSettingDTO dto = new PrescriptionSettingDTO();
        BeanUtils.copyProperties(prescriptionSetting, dto);
        return ResultVO.success(dto);
    }

    //==========================================================================================================
    @PostMapping("/member/setting/edit")
    @ApiOperation("人员设置 -- 添加")
    @ApiOperationSupport(ignoreParameters = {"memberList[0].id", "memberList[0].hospitalId"})
    public ResultVO editPrescriptionMember(@RequestBody PrescriptionMemberEditDTO memberEditDTO) {
        settingService.editPrescriptionMember(memberEditDTO);
        return ResultVO.success();
    }

    @DeleteMapping("/member/setting/delete")
    @ApiOperation("人员设置 -- 删除")
    public ResultVO deletePrescriptionMember(@RequestBody PrescriptionMemberDeleteDTO deleteDTO) {
        settingService.deletePrescriptionMember(deleteDTO);
        return ResultVO.success();
    }

    @GetMapping("/member/setting/list/{hospitalId}")
    @ApiOperation("人员设置 -- 列表")
    public ResultVO<List<PrescriptionCheckMemberDTO>> listPrescriptionCheckMember(@PathVariable Integer hospitalId) {
        return ResultVO.success(settingService.listPrescriptionCheckMember(hospitalId));
    }

    //==========================================================================================================

    @ApiOperation("处方温馨提示 -- 添加修改")
    @PostMapping("/tip/edit")
    public ResultVO<PrescriptionTips> editPrescriptionTips(@RequestBody PrescriptionTips tip) {
        return ResultVO.success(tipsService.editPrescriptionTips(tip));
    }

    @ApiOperation("处方温馨提示 -- 删除")
    @DeleteMapping("/tip/delete/{tipId}")
    public ResultVO<PrescriptionTips> editPrescriptionTips(@PathVariable Integer tipId) {
        tipsService.deletePrescriptionTips(tipId);
        return ResultVO.success();
    }

    @ApiOperation("处方温馨提示 -- 列表")
    @GetMapping("/list/tips/{hospitalId}")
    public ResultVO<List<PrescriptionTipsDTO>> listHospitalPrescriptionTips(@PathVariable Integer hospitalId) {
        return ResultVO.success(tipsService.listHospitalPrescriptionTips(hospitalId));
    }

    //==========================================================================================================
    @ApiOperation("处方中药处理方式 -- 添加修改")
    @PostMapping("/note/edit")
    public ResultVO<PrescriptionNoteType> editPrescriptionNoteType(@RequestBody PrescriptionNoteType type) {
        return ResultVO.success(prescriptionNoteTypeService.editHospitalNote(type));
    }

    @ApiOperation("处方中药处理方式 -- 删除")
    @DeleteMapping("/note/delete/{id}")
    public ResultVO<PrescriptionNoteType> editPrescriptionNoteType(@PathVariable Integer id) {
        prescriptionNoteTypeService.deleteHospitalNote(id);
        return ResultVO.success();
    }

    @ApiOperation("处方中药处理方式 -- 列表")
    @GetMapping("/note/list/{hospitalId}")
    public ResultVO<List<PrescriptionNoteType>> hospitalNoteList(@PathVariable Integer hospitalId) {
        return ResultVO.success(prescriptionNoteTypeService.hospitalNoteList(hospitalId));
    }


    private PrescriptionNoteTypeService prescriptionNoteTypeService;

    private PrescriptionSettingService settingService;

    private PrescriptionTipsService tipsService;

    @Autowired
    public void setSettingService(PrescriptionSettingService settingService) {
        this.settingService = settingService;
    }

    @Autowired
    public void setTipsService(PrescriptionTipsService tipsService) {
        this.tipsService = tipsService;
    }

    @Autowired
    public void setPrescriptionNoteTypeService(PrescriptionNoteTypeService prescriptionNoteTypeService) {
        this.prescriptionNoteTypeService = prescriptionNoteTypeService;
    }
}
